<script>
export default {
	 onLaunch:function(e) {
		new Promise((resolve, reject) => {
			this.$api('config', "get").then((res) => {
				this.$store.commit('config/setConfig', res.data[0])
				resolve(res.data[0])
			})
		}).then(() => {
			//#ifdef MP-WEIXIN
			uni.showLoading({
				title: "登陆中"
			})
			uni.login({ 
				provider: 'weixin'
			}).then(code => {
				code = code[1].code
				this.$api('user-center', 'loginByWeixin', {
					code,
					invitation: e.query.invitation || 0,
				}).then(res => {
					if (res.code === 0) {
						uni.hideLoading()
						// 如果使用2.7.15及以上版本建议存为uni_id_token
						uni.setStorageSync('uniIdToken', res.token)
						this.$store.commit('user/login', res.userInfo)
						uni.setStorageSync('uni_id_token_expired', res.tokenExpired)
						this.$isResolve()
					}
				})
		
			})
			//#endif
			//#ifndef MP-WEIXIN
			this.$isResolve() //放行app
			//#endif
		})
		//#ifdef H5
		this.$api('user-center','checkToken').then(res=>{
			if(res.code!==0){
				//处理过期
				uni.navigateTo({
					url:"../../../pages/user/login",
					fail:(err)=>{
					console.log(err)	
					}
				})
			}
		})
		//#endif
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	}
};
</script>

<style>
/* 引入remixicon图标库 */
	@import 'static/libs/remixicon.css';
</style>
